<?php defined('SYSPATH') OR die('No direct access allowed.');

class Order_Controller extends Controller 
{
	public function index()
	{
		$authentic = new Auth;
		if ($authentic->logged_in())
		{
			if ($product_id = $this->input->get('product_id'))
			{
				$order = ORM::factory('order'); 
				$product = ORM::factory('product'); 
				$product->find($product_id);
				if ($product->count_last_query())
				{
					$order->user_id = $authentic->get_user()->id;
					$order->product_id = $product_id;
					if ($order->save())
					{
						return $order->id;
					}
				}
				
			}
		}

		exit();
		url::redirect();
	}
}


